package com.demo.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/accp")
public class IndexController {
	@RequestMapping("/index")
	public String index(Model model,String name,int no){
		model.addAttribute("message", "使用注解实现控制器controller");
		model.addAttribute("name", "controller接收到的数据"+name+"，"+no);
		return "index";
	}
	
	@RequestMapping("/p1")
	public String p1(String[] hobby){
		System.out.println(hobby.length);
		for (String string : hobby) {
			System.out.println(string);
		}
		return "index";
	}
	
	@RequestMapping("/p2")
	public ModelAndView p2(){
		ModelAndView mv =new ModelAndView();
		Map<String, Object> map =new HashMap<String, Object>();
		map.put("message", "5");
		map.put("ddd", "88");
		mv.setViewName("index");
		mv.addAllObjects(map);
		return mv;
	}
	
	@RequestMapping("/p3")
	public String p3(Map<String, Object> map){
		map.put("message", "djdjdd");
		return "index";
	}
	
	@RequestMapping(value="/p4",params="name",method=RequestMethod.POST)
	public String p4(Model model,String name){
		model.addAttribute("message",name);
		return "index";
	}
	
	@RequestMapping("/p5")
	public String p5(Integer id){
		System.out.println("id"+id);
		return "index";
	}
	
	@RequestMapping("/p6")
	public String p6(@RequestParam(name="id",required=false,defaultValue="0")int id){
		System.out.println("id"+id);
		return "index";
	}
	
}
